package b3.widget.home.operation
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.util.*;
	import b3.widget.basic.*;
	import b3.widget.tab.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;

	public class WeaponSelectPane extends Tab
	{
		public function WeaponSelectPane(target:BuildingModel)
		{
			//背景
			var PaneBgr:Class = ResourceHelper.getInstance().getClassByName("WeaponSelectPaneBgr");
			var pangBgr:Sprite = new PaneBgr();
			addChild(pangBgr);
			super("", 4, 1);
			this.anchor = BasicWidget.ANCHOR_MIDDLE_MIDDLE;
			//设置页码位置
			this.setPagePos(103, 80);
			pageSelector.hideNumArea();
			pageSelector.x = 68;
			pageSelector.y = 110;
			pageSelector.pageUp.x = 0;
			pageSelector.pageUp.y = 0;
			pageSelector.firstPage.x = 0;
			pageSelector.firstPage.y = 30;
			pageSelector.pageDown.x = 425;
			pageSelector.pageDown.y = 0;
			pageSelector.lastPage.x = 425;
			pageSelector.lastPage.y = 30;
			//标题
			var titleField:TextField = new TextField();
			titleField.selectable = false;
        	titleField.autoSize = TextFieldAutoSize.CENTER;
			titleField.defaultTextFormat = new TextFormat(BFont.fontName, 20, 0xFFFFFF, true);
			titleField.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleField.x = this.width / 2;
			titleField.y = 20;
			titleField.text = "请选择导弹！";
			addChild(titleField);
			//加载可用武器
			var buildings:Object = PlayerManager.getInstance().me.townModel.buildings;
			for (var i:String in buildings)
			{
				var buildingModel:BuildingModel = buildings[i];
				var buildingConfig:BuildingConfig = Config.buildingConfigs[buildingModel.buildingIndex];
				//如果导弹没有封顶 无法使用
				if (buildingConfig.type == BuildingConfig.WEAPON && buildingModel.roofType != -1)
				{
					var weaponSelectItem:WeaponSelectItem = new WeaponSelectItem(buildingModel, target);
					weaponSelectItem.addEventListener(MouseEvent.CLICK, onCloseButtonClick);
					addItem(weaponSelectItem, 92, 133.25);
				}
			}
			//关闭按钮
			var CloseButton:Class = ResourceHelper.getInstance().getClassByName("CloseButton1");
			var closeButton:BasicButton = new BasicButton(CloseButton);
			closeButton.x = (this.width - closeButton.width) / 2;
			closeButton.y = 202;
			addChild(closeButton);
			closeButton.addEventListener(MouseEvent.CLICK, onCloseButtonClick);
		}
		
		private function onCloseButtonClick(event:Event):void
		{
			close();
		}
		
	}
}